package org.dizem.intellipainter.component;

import org.dizem.intellipainter.AppConstants;
import org.dizem.intellipainter.MainFrame;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * User: dizem@126.com
 * Time: 12-2-18 下午10:10
 */
public class AboutDialog extends JDialog {
	private static final Font font = new Font("微软雅黑", Font.PLAIN, 12);

	public AboutDialog(MainFrame mainFrame) {
		setModal(true);
		setTitle(AppConstants.APP_NAME + " " + AppConstants.APP_VERSION);
		setMinimumSize(new Dimension(350, 120));
		setLocationRelativeTo(mainFrame);
		setLayout(new BorderLayout());
		add(createCenter(), BorderLayout.CENTER);
		setVisible(true);
		setResizable(false);
	}

	private Component createCenter() {
		JPanel panel = new JPanel(new GridLayout(4, 1, 5, 0));
		Box author = Box.createHorizontalBox();
		author.add(new MyLabel("  Author: "));
		final JLabel name = new MyLabel("<html><a>丁智敏</a></html>");
		name.setForeground(new Color(0x1689F4));
		name.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				try {
					Desktop.getDesktop().browse(new URI("http://weibo.com/dizem"));
				} catch (IOException e1) {
					e1.printStackTrace();
				} catch (URISyntaxException e1) {
					e1.printStackTrace();
				}
			}
		});
		author.add(name);
		panel.add(author);
		panel.add(new MyLabel("<html>&nbsp;&nbsp;Copyright&copy 2011-2012 <a href='http://dizem.org'>dizem.org<a> All Rights Reserved</html>"));
		panel.add(new MyLabel("  本程序完全免费，禁止用于任何商业用途，个人用户基于学习"));
		panel.add(new MyLabel("  和研究目的的传播、修改将不受限制。"));
		return panel;
	}

	private class MyLabel extends JLabel {

		private MyLabel(String text) {
			super(text);
			setHorizontalAlignment(LEFT);
			setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					try {
						Desktop.getDesktop().browse(new URI("http://hi.baidu.com/dizemmm"));
					} catch (IOException e1) {
						e1.printStackTrace();
					} catch (URISyntaxException e1) {
						e1.printStackTrace();
					}
				}
			});
		}

		@Override
		public Font getFont() {
			return font;
		}
	}

}
